package com.css.fxfzypg.modules.report.controller;


import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.report.entity.ReportTemplateEntity;
import com.css.fxfzypg.modules.report.queryParams.ReportTemplateEntityQueryParams;
import com.css.fxfzypg.modules.report.service.ReportTemplateService;
import com.css.fxfzypg.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 报告模板接口
 */
@RestController
@RequestMapping("/fxfzypg/report")
@Slf4j
public class ReportTemplateController {


    @Resource
    private ReportTemplateService reportTemplateService;

    /*
    * 添加报告接口
    *
    * */
    @PostMapping("/saveReportTemplate")
    public RestResponse saveReportTemplate(@RequestBody ReportTemplateEntity reportTemplateEntity) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(reportTemplateService.saveReportTemplate(reportTemplateEntity));
        } catch (Exception e) {
            log.error("新增报告模板失败", e);
            restResponse = RestResponse.fail("新增报告模板失败!");
        }
        return restResponse;
    }


    /*
    * 查询报告列表接口
    * */
    @GetMapping("/getAllReportTemplate")
    public RestResponse getAllReportTemplate(HttpServletRequest request, ReportTemplateEntityQueryParams reportTemplateEntityQueryParams) {
        RestResponse restResponse = null;
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            reportTemplateEntityQueryParams.setCurPage(curPage);
            reportTemplateEntityQueryParams.setPageSize(pageSize);
            Map<String,Object> map = reportTemplateService.getAllReportTemplate(reportTemplateEntityQueryParams);
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            log.error("查询报告模板信息失败!", e);
            restResponse = RestResponse.fail("查询报告模板信息失败");
        }
        return restResponse;
    }

    /*
     * 查询报告列表接口(查询全部，无条件，不分页)
     * */
    @GetMapping("/getReportTemplateByType")
    public RestResponse getReportTemplateByType(String rtType) {
        return reportTemplateService.getReportTemplateByType(rtType);
    }


    /*
    *
    * 删除报告接口
    * */
    @PostMapping("/delReportTemplate/{ids}")
    public RestResponse delReportTemplate(@PathVariable("ids") List<String> ids) {
        RestResponse restResponse = null;
        try {
            reportTemplateService.delReportTemplate(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除报告模板失败!", e);
            restResponse = RestResponse.fail("删除报告模板失败!");
        }
        return restResponse;
    }


}
